{extend name="../../../view/public/base" /}
{block name="css"}
<style>

</style>
{/block}
{block name="body"}
<form class="layui-form layui-form-pane" id="form">




    <input type="hidden" id="id" name="id" value="{$entity.id? $entity.id : 0}"/>
    <blockquote class="layui-elem-quote"><h3><i class="layui-icon">&#xe611;</i>&nbsp&nbsp&nbsp
        <span style="color: red;">添加修改</span>

    </h3></blockquote>



    <style type="text/css">
        .select-test{position: absolute;max-height: 500px;height: 350px;overflow: auto;width: 100%;z-index: 123;display: none;border:1px solid silver;top: 42px;}
        .layui-show{display: block!important;}
    </style>
    <div class="layui-form layui-form-panel">

        <div class="layui-form-item">
            <label class="layui-form-label"><span style = "color:red;">*</span>分类名称：</label>
            <div class="layui-input-block" >
                <input  type="text" name="title" lay-verify="title"
                        autocomplete="off" placeholder="请输入配置分类名称" class="layui-input"
                        value="{$entity.title? $entity.title : null}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span style = "color:red;">*</span>分类字段：</label>
            <div class="layui-input-block" >
                <input  type="text" name="tab_name" lay-verify="tab_name"
                        autocomplete="off" placeholder="请输入配置分类字段" class="layui-input"
                        onkeyup="this.value=this.value.replace(/[^\w_]/g,'');"
                        value="{$entity.tab_name? $entity.tab_name : null}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span style = "color:red;">*</span>分类类型：</label>
            <div class="layui-input-block">
                {if !empty($entity.type)}
                <input type="radio" name="type"  value="1"  title="系统配置"  lay-filter="type"  {$entity.type==1 ? 'checked':'' } >
                <input type="radio" name="type"  value="2"  title="插件配置"  lay-filter="type" {$entity.type==2 ?  'checked':'' }>
                <input type="radio" name="type"  value="3"  title="应用配置"  lay-filter="type" {$entity.type==3 ?  'checked':'' }>
                <!--<input type="radio" name="type"  value="4"  title="其他配置"  lay-filter="type" {$entity.type==4 ?  'checked':'' }>-->
                {else/}
                <input type="radio" name="type"  value="1"  title="系统配置"  lay-filter="type"  checked >
                <input type="radio" name="type"  value="2"  title="插件配置"  lay-filter="type"  >
                <input type="radio" name="type"  value="3"  title="应用配置"  lay-filter="type"  >
                <!--<input type="radio" name="type"  value="4"  title="其他配置"  lay-filter="type"  >-->
                {/if}
            </div>
        </div>

        <div class="layui-form-item" id="miniapp" {if empty($entity.type)||$entity.type!='3' } style="display: none" {/if}>
        <label class="layui-form-label">应用</label>
        <div class="layui-input-block">

            <select name="dir" id="miniapp_name" lay-filter="miniapp_name" >
                <option value="">请选择</option>
                {if !empty($entity.dir)}
                {volist name="miniapp" id="vo" key="k"}
                <option value="{$vo.dir}" {eq name="vo.dir" value="$entity.dir"} selected=""  {/eq}>{$vo.title}</option>
                {/volist}
                {else/}
                {volist name="miniapp" id="vo"  key="k"}
                <option value="{$vo.dir}" >{$vo.title}</option>
                {/volist}
                {/if}
            </select>

        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label"><span style = "color:red;">*</span>分类状态：</label>
        <div class="layui-input-block">
            {if !empty($entity.is_show)}
            <input type="radio" name="is_show"  value="1"  title="显示"  {$entity.is_show==1 ? 'checked':'' } >
            <input type="radio" name="is_show"  value="0"  title="隐藏"  {$entity.is_show==0 ?  'checked':'' }>
            {else/}
            <input type="radio" name="is_show"  value="1"  title="显示" checked >
            <input type="radio" name="is_show"  value="0"  title="隐藏">

            {/if}
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label"><span style = "color:red;">*</span>配置权限：</label>
        <div class="layui-input-block">
            {if !empty($entity.scopes)}
            <input type="radio" name="scopes"  value="common"  title="平台"  disabled {$entity.scopes=='common' ? 'checked':'' } >
            <!--<input type="radio" name="scopes"  value="admin"  title="总后台"  disabled {$entity.scopes=='admin' ?  'checked':'' }>-->
            <input type="radio" name="scopes"  value="member"  title="租户"  disabled {$entity.scopes=='member' ?  'checked':'' }>
            {else/}
            <input type="radio" name="scopes"  value="common"  title="平台" checked >
            <!--<input type="radio" name="scopes"  value="admin"  title="总后台">-->
            <input type="radio" name="scopes"  value="member"  title="租户">
            {/if}
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label"><span style="color: red; font-size: 20px"></span>选择图标：</label>
            <div class="layui-input-inline">
                <input  type="text" name="icon" id="icon" lay-verify="icon"
                        autocomplete="off"  placeholder="单机图标按钮选择图标" class="layui-input"
                        value="{$entity.icon? $entity.icon : null} " >
            </div>
        </div>
        <div class="layui-inline">
            <div class="layui-input-inline">
                <button type="button" class="layui-btn layui-btn-primary layui-btn-sm" onclick="getNum()">选择图标</button>

            </div>

        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label"><span style="color: red; font-size: 20px">*</span>分类说明：</label>
        <div class="layui-input-block">
                      <textarea placeholder="请输入默认值" class="layui-textarea"
                                lay-verify="value" id ='rtext'>{$entity.desc? $entity.desc : null}</textarea>
            <input type="hidden" name="desc" value="{$entity.desc? $entity.desc : null}"/>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">权重：</label>
        <div class="layui-input-block" >
            <input  type="number" name="sort" lay-verify="sort"
                    autocomplete="off" placeholder="请输入权重,影响显示顺序" class="layui-input"
                    value="{$entity.sort? $entity.sort : null}">
        </div>
    </div>


</form>

{/block}

{block name="js"}

<script>

    var table;
    var laydate;
    var util;
    var	$;
    var result = "";
    var form;
    var auth_status = '';
    var layedit;
    var layedit_index;
    var dtree;
    layui.use(['form', 'table','util','laydate','layer','element','layedit'],function() {
        $ = layui.jquery;
        var util = layui.util,layer = layui.layer ,element = layui.element;
        table = layui.table;
        form = layui.form;
        laydate = layui.laydate;
        layedit = layui.layedit;
        layedit.set({
            uploadImage: {
                url: "{:Url('/manage/publicCommon/uploadEditor')}?layui=1" //接口url
                ,type: 'post' //默认post
            }
        });
        layedit_index = layedit.build('rtext'); //建立编辑器

        form.on('radio(type)', function (data) {
            showAppName(data.value);
        });

    })

    //选择图标
    function getNum(){

        layer.open({
            type: 2,
            title: '图标列表',
            shade: 0.8,
            //closeBtn: 0, //不显示关闭按钮
            shade: [0],
            shadeClose: true,//单机空白处消失
            maxmin: true,
            //anim: 4, //动画类型
            area: ['40%','90%'],
            content:"{:Url('PublicCommon/icon')}",
            btn: ['选择图标'],
            yes: function(index, layero){

                var nodeName = window["layui-layer-iframe" + index];//父页面引用
                var icon = nodeName.getIcon();
                if(icon!=false){
                    $('#icon').val(icon);
                    layer.close(index);
                    //处理重复提交
                }





            }
        });
    }
    function getId(){
        return $('#id').val();
    }

    function getSaveData(){

        var title = $("input[name='title']").val();//配置分类
        var tab_name = $("input[name='tab_name']").val();//配置分类英文标识
        var icon = $("input[name='icon']").val();//图标
        var type = $("input[name='type']:checked").val();//主播状态
        var dir = $("#miniapp_name").val();//主播状态
        var is_show = $("input[name='is_show']:checked").val();//房间状态
        var scopes = $("input[name='scopes']:checked").val();

        var desc = layedit.getContent(layedit_index);//排序
        $("input[name='desc']").val(desc);//赋值
        if(title == ''){
            layer.msg("请填写配置分类名称", {
                icon : 2,
                time : 1500
            });
            return false;
        }

        if(tab_name == ''){
            layer.msg("请填写配置分类字段", {
                icon : 2,
                time : 1500
            });
            return false;
        }

        if(type == ''){
            layer.msg("请填写分类类型", {
                icon : 2,
                time : 1500
            });
            return false;
        }
        if(is_show == ''){
            layer.msg("请填写显示状态", {
                icon : 2,
                time : 1500
            });
            return false;
        }
        if(type =='3'){
            console.log(dir);
            if(!dir){
                layer.msg("请选择应用", {
                    icon : 2,
                    time : 1500
                });
                return false;
            }
            if(scopes =='common'){
                layer.msg("应用配置只能是租户配置", {
                    icon : 2,
                    time : 1500
                });
                return false;
            }
        }





        return $('#form').serialize();
    }

    /**
     * 显示隐藏应用选择
     */
    function showAppName(value) {
        //显示应用选择
        if(value =='3'){
            $("#miniapp").show();
        }else{
            //隐藏应用选择
            $("#miniapp").hide();
            //清空select 值
            $("#miniapp_name").val('');
            form.render('select');
        }

    }

</script>
{/block}